package com.xu.sso.core.enums;

import java.util.HashMap;
import java.util.Map;

public enum ErrorMessage {

    Success("Success","成功"),
    UnknowError("UnknowError","未知异常"),
    IllegalArgumentException("IllegalArgumentException","参数异常"),

    IpAddrError("IpAddrError","此用户已在别处登录"),
    AppIdNotFound("AppIdNotFound","APPID不能为空"),
    UsernameNotFound("UsernameNotFound","用户名不能为空"),
    PasswordNotFound("PasswordNotFound","密码不能为空"),
    TokenNotFound("TokenNotFound","token不能为空"),
    RequestIdNotFound("RequestIdNotFound","请求ID不能为空"),
    SignNotFound("SignNotFound","签名串不能为空"),
    MethodNotFound("MethodNotFound","请求方法不能为空"),
    NoAppError("NoAppError", "该应用未注册"),
    NoUserError("NoUserError", "该用户不存在"),
    NoAppPower("NoAppPower","用户无权限访问此应用"),
    PasswordError("PasswordError", "密码错误"),
    NoRedirectUrl("NoRedirectUrl", "回调链接为空，请从原系统重新请求"),
    NoPower("NoPower", "无此权限"),
    LogonExpires("LogonExpires","登录已过期，请重新登录"),
    AppStop("AppStop","应用已停用，请联系管理员"),
    RedisError("RedisError","redis操作异常，请联系管理员"),
    EmailAddressError("EmailAddressError","邮箱地址不正确，请输入正确的公司邮箱"),
    UserExist("UserExist","用户已存在"),
    UserEmailNotMatch("UserEmailNotMatch","用户邮箱不匹配"),
    UserEmailIsEmpty("UserEmailIsEmpty","用户邮箱为空"),
    NotLeader("NotLeader","非负责人权限"),
    AddUserError("AddUserError","添加用户失败"),
    UpdateUserError("UpdateUserError","更新用户信息失败"),
    AppExist("AppExist","APP已存在，请勿重复注册"),
    AppNotExist("AppNotExist","APP不存在"),
    AppRoleExist("AppRoleExist","应用角色已存在"),
    AddAppDataError("AddAppDataError","添加应用失败"),
    AddAppUserError("AddAppUserError","添加操作人失败"),
    UpdateAppError("UpdateAppError","更新APP失败"),
    DeleteAppError("DeleteAppError","删除APP失败"),
    UpdatePasswordError("UpdatePasswordError","更新密码失败"),
    DeleteAppUserError("DeleteAppUserError","删除应用用户授权失败"),
    AddAppRoleError("AddAppRoleError","添加应用角色失败"),
    ChangeAppRoleStatusError("ChangeAppRoleStatusError","变更角色状态失败"),
    UpdateAppRoleError("UpdateAppRoleError","更新应用角色失败"),
    DeleteAppRoleError("DeleteAppRoleError","删除应用角色失败"),
    DeleteAppUserRoleError("DeleteAppUserRoleError","删除应用用户角色失败"),
    AddAppUsersError("AddAppUsersError","添加应用用户失败"),
    AddAppUserRolesError("AddAppUserRolesError","用户角色授权失败"),
    DeleteAppUserRolesError("DeleteAppUserRolesError","删除用户角色失败"),
    AddAppLeaderError("AddAppLeaderError","添加项目负责人失败"),
    AppLeaderNumMaxError("AppLeaderNumMaxError","项目负责人最多3人"),
    AppLeaderNumMinError("AppLeaderNumMinError","项目负责人至少1人"),
    AddResourcesRoleError("AddResourcesRoleError","添加资源权限失败"),
    AddResourcesError("AddResourcesError","添加资源失败"),
    UpdateResourcesError("UpdateResourcesError","更新资源失败"),
    DeleteResourcesError("DeleteResourcesError","删除资源失败"),
    DeleteResourcesRoleError("DeleteResourcesRoleError","移除资源权限失败"),
    DeleteUserError("DeleteUserError","注销用户失败"),
    CheckSignError("CheckSignError","签名验证异常"),
    SignError("SignError","签名加密异常"),
    KeyNotFound("KeyNotFound","签名秘钥为空"),
    AppNotAuthorization("AppNotAuthorization","应用没有授权"),
    AddDepError("AddDepError","添加部门失败"),
    UpdateDepError("UpdateDepError","更新部门失败"),
    DeleteDepError("DeleteDepError","删除部门失败"),
    DepExist("DepExist","部门已存在"),
    AddApiAuthError("AddApiAuthError","添加api授权失败"),
    ChangeApiStatusError("ChangeApiStatusError","变更授权状态失败"),
    UpdateApiAuthError("UpdateApiAuthError","更新授权失败"),
    DeleteApiAuthError("DeleteApiAuthError","删除授权失败"),
    ;


    private String errCode;
    private String errMsg;

    private ErrorMessage(String errCode, String errMsg) {
        this.errCode = errCode;
        this.errMsg = errMsg;
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    private static Map<String, ErrorMessage> errorMessages = null;

    public static ErrorMessage getErrorMessage(String errCode) {
        if (null == errorMessages) {
            synchronized (ErrorMessage.class) {
                if (null == errorMessages) {
                    errorMessages = new HashMap<>();
                    for (ErrorMessage errorMessage : values()) {
                        errorMessages.put(errorMessage.getErrCode(), errorMessage);
                    }
                }
            }
        }
        return errorMessages.get(errCode);
    }

}
